﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YwhCore
{
    public class MeetingService
    {
        /// <summary>
        /// 获取会议列表
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public static QueryRsp<Meeting> List(int PageNumber, int PageSize)
        {
            long l = 0;
            QueryRsp<Meeting> query = new QueryRsp<Meeting>();
            query.Items = ConfigService.Fsql.Select<Meeting>().Count(out l).Page(PageNumber, PageSize).ToList();
            query.Total = (int)l;
            return query;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="meeting"></param>
        /// <returns></returns>
        public static QueryRsp<Meeting> Save(Meeting meeting)
        {
            QueryRsp<Meeting> query = new QueryRsp<Meeting>();

            if (meeting.MeetingId > 0)//编辑
            {
                var repo = ConfigService.Fsql.GetRepository<Meeting>();
                int num = repo.Update(meeting);
                if (num == 0)
                {
                    query.Error = "没有更新成功";
                }
            }
            else
            {
                long lid = ConfigService.Fsql.Insert<Meeting>(meeting).ExecuteIdentity();
                if (lid > 0)
                {
                    meeting.MeetingId = (int)lid;
                }
                else
                {
                    query.Error = "添加记录失败";
                }
            }

            query.Item = meeting;
            return query;
        }

    }
}